import { FontLoader } from "../three/FontLoader";
import TextGeometry from '../three/TextGeometry';

let loader = new FontLoader();
let font;


async function getFont() {
    if (font) {
        return font;
    }
    loader.load( '/assets/fonts/helvetiker_regular.typeface.json', function (_font) {
        font = _font
    });
    for (let i = 0; i < 10; i++) {
        if (font) {
            return font;
        }
        await sleep(1000);
    }
}

function sleep (time) {
    return new Promise((resolve) => setTimeout(resolve, time));
}

async function createText(text) {
    await getFont()

    var geometry = new TextGeometry(text, {
        font: font,
        size: 80,
        height: 5,
        curveSegments: 12,
        bevelEnabled: true,
        bevelThickness: 10,
        bevelSize: 8,
        bevelSegments: 5
    });

    console.log(geometry)

    return geometry;
}

export default {
    createText
}